package aip2011.controller.localita.dettaglio;


import javax.servlet.http.HttpServletResponse;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.util.ResponseLocator;

import aip2011.model.ImmagineLocalita;
import aip2011.service.ImmagineLocalitaService;

public class ImageController extends Controller {
    
    
    private ImmagineLocalitaService service=new ImmagineLocalitaService();
  
    @Override
    public Navigation run() throws Exception {
        if(asKey("key")!=null)
        {
                HttpServletResponse response = ResponseLocator.get();
                byte[] bytes ;
                ImmagineLocalita data = service.getData(asKey("key"), asLong("v"));
                bytes = service.getBytes(data);
                response.getOutputStream().write(bytes);
                response.setContentType("image/JPEG");
                return null;
        }
        return null;
    }
}